package edu.mobbuzz.page.menu;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import edu.mobbuzz.page.menu.rsschannel.RSSChannelPage;
import edu.mobbuzz.util.string.MenuString;
import edu.mobbuzz.util.theme.Theme;
import java.io.IOException;

public class RSSChannelMenu extends Menu{
    private Form rssChannelForm;
    private Container rssChannelPanel; 
    
    private Label menuTitle;
    private Label menuIconLabel;
    private Label menuDescription;
    private Image menuIcon;   
    
    public RSSChannelMenu(){
        rssChannelForm = new Form(){
            public void keyPressed(int keyCode) {
                gameActionPerformed(keyCode);
            }        
        };             
        rssChannelPanel = new Container();
        
        menuTitle = new Label(getMenuTitle());
        menuDescription = new Label();
        try {
            menuIcon = Image.createImage("/icons/rss.gif"); //Theme.getResources().getImage("rss_channel.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        menuIconLabel = new Label(menuIcon);  
    }
    public void showPage(){ 
        menuIconLabel.setAlignment(Component.CENTER);
        menuIconLabel.getStyle().setMargin(50, 0, 0, 0);
        menuIconLabel.getStyle().setBgTransparency(0);
        
        menuTitle.setAlignment(Component.LEFT);
        menuTitle.getStyle().setMargin(5, 0, 5, 0);
        menuTitle.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        menuTitle.getStyle().setFgColor(0xF59FBC);
        menuTitle.getStyle().setBgTransparency(0);
        
        menuDescription.setText("Subscribe your favorite RSS");      
        menuDescription.setAlignment(Component.LEFT);
        menuDescription.getStyle().setFont(Theme.getFontDescriptionStyle("SansSerif"));
        menuDescription.getStyle().setFgColor(0xFFFFFF);
        menuDescription.getStyle().setMargin(0, 0, 5, 0);         
        menuDescription.getStyle().setBgTransparency(0);
        
        rssChannelForm.setLayout(new BorderLayout());        
        rssChannelPanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        
        rssChannelPanel.addComponent(menuIconLabel);
        rssChannelPanel.addComponent(menuTitle);
        rssChannelPanel.addComponent(menuDescription);
        //rssChannelMenuPanel.getStyle().setBgImage(Theme.getBackground());
        
        rssChannelForm.addComponent(BorderLayout.CENTER, rssChannelPanel);
        
        rssChannelForm.addCommand(getExitCmd());
        rssChannelForm.addCommand(getOnlineCmd());
        rssChannelForm.addCommand(getSignOutCmd());
        rssChannelForm.addCommand(new Command("Open") {
            public void actionPerformed(ActionEvent evt) {
               displayRSSChannel();
            }
        });
        
        
        rssChannelForm.setCommandListener(getActionlistener());
        rssChannelForm.show();
    }
    
    public String getMenuTitle() {
        return MenuString.RSSCHANNEL;
    }

    public void gameActionPerformed(int keyCode){
        int game = Display.getInstance().getGameAction(keyCode);
        if(game == Display.GAME_FIRE){
            displayRSSChannel();
        }else if(game == Display.GAME_RIGHT){
            getRSSChannelTransitionRight();
        }else if(game == Display.GAME_LEFT){
            getRSSChannelTransitionLeft();
        }
    }
    
    public void getRSSChannelTransitionRight(){
       rssChannelForm.setTransitionOutAnimator(Theme.getTransitionOut());
       ContactMenu contactMenu = new ContactMenu();
       contactMenu.setExitCmd(getExitCmd());
       contactMenu.setActionlistener(getActionlistener());
       contactMenu.setMessaging(getMessaging());
       contactMenu.showPage();
    }
    
    public void getRSSChannelTransitionLeft(){
       rssChannelForm.setTransitionOutAnimator(Theme.getTransitionIn());
       CategoryMenu categoryMenu = new CategoryMenu();
       categoryMenu.setExitCmd(getExitCmd());
       categoryMenu.setActionlistener(getActionlistener());
       categoryMenu.setMessaging(getMessaging());
       categoryMenu.showPage();
    }

    public void displayRSSChannel() {
        RSSChannelPage rssChannelPage = new RSSChannelPage();
        rssChannelPage.setExitCmd(getExitCmd());
        rssChannelPage.setActionlistener(getActionlistener());
        rssChannelPage.setMessaging(getMessaging());
        rssChannelPage.showPage();
    }
	 
}
 
